package com.xiaoxin.experience.service.hls.common;

import com.xiaoxin.experience.util.StringUtil;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

/**
 * @author xiaoxin
 */
@Setter
@Getter
public class HlsEncryptInfo implements Serializable {

    private static final long serialVersionUID = -3912818907082894044L;

    private String method;

    private String key;

    private String iv = "";

    private byte[] keyBytes;

    public boolean isEmpty()
    {
        return StringUtil.isBlank(key) && Objects.isNull(keyBytes);
    }

    public byte[] getKey()
    {
        if (StringUtil.isBlank(key))
        {
            return keyBytes;
        }
        return key.getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public String toString()
    {
        return "HlsEncryptInfo{" +
                "method='" + method + '\'' +
                ", key='" + key + '\'' +
                ", iv='" + iv + '\'' +
                '}';
    }
}
